<?php // vim:fenc=utf-8:filetype=php:ts=4

require('../config/net.php');

$info=$_GET['info'];
$net = new Net();
$out = $net->readDataFromSystem();
$host=$out['hostname'];

switch($info) {
    case "uptime":
        passthru("/usr/bin/uptime");
        break;
    case "all":
        $json['hostname'] = $host;
        $json['uptime'] = exec("/usr/bin/uptime");
        $json['systime'] = exec("/bin/date");
        $json['version'] = exec("cat /etc/lab/lab-version");

        $filearray = file("/etc/lab/lab.conf");
        if ( $filearray == false ) {
            $json['inst_type'] = "UNKNOWN";
        }
        foreach ( $filearray as $arrval ) {
            if(preg_match('/INSTALL_TYPE=LIVE.*/', $arrval)) {
                $json['inst_type'] = "System is running off a LIVE CD";
                break;
            }
            else if(preg_match('/INSTALL_TYPE=ONDISK.*/', $arrval)) {
                $json['inst_type'] = "System is running off the hard-drive";
                break;
            }
        }
        print(json_encode($json));
        break;
    default:
        break;
}

?>
